/*****************************************************************************
 * at24cxx.c
 *
 * Copyright (C) 2019 Jeasonvor <1101627719@qq.com>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 ****************************************************************************/

/*****************************************************************************
 * Included Files
 ****************************************************************************/

#include "at24cxx.h"

/*****************************************************************************
 * Trace Definitions
 ****************************************************************************/

#define DEVICE_ADDR

/*****************************************************************************
 * Pre-processor Definitions
 ****************************************************************************/

/*****************************************************************************
 * Private Types
 ****************************************************************************/

struct at24cxx_io {
    uint8_t (*i2c_read_byte)(uint16_t addr);
    void (*i2c_write_byte)(uint16_t addr, uint8_t data);
};

/*****************************************************************************
 * Private Function Prototypes
 ****************************************************************************/

/*****************************************************************************
 * Private Data
 ****************************************************************************/

static struct at24cxx_io dev_hdl;

/*****************************************************************************
 * Public Data
 ****************************************************************************/

/*****************************************************************************
 * Private Functions
 ****************************************************************************/

static uint8_t device_24cxx_read_byte(uint16_t addr)
{
}

static void device_24cxx_write_byte(uint16_t addr, uint8_t data)
{

    dev_hdl.i2c_write_byte();
}

/*****************************************************************************
 * Public Functions
 ****************************************************************************/

int at24cxx_init(uint8_t (*readbyte)(uint16_t addr),
                 void (*writebyte)(uint16_t addr, uint8_t wData))
{
    dev_hdl.i2c_read_byte  = readbyte;
    dev_hdl.i2c_write_byte = writebyte;

    return (0);
}

int at24cxx_read(uint16_t addr, uint8_t *rData, uint16_t len)
{
    uint8_t *pBuf  = rData;
    uint16_t point = addr;
    while (len) {
        *pBuf = device_24cxx_read_byte(point);
        point++;
        pBuf++;
        len--;
    }

    return (0);
}

int at24cxx_write(uint16_t addr, uint8_t *wData, uint16_t len)
{
    uint8_t *pBuf = wData;
    while (len--) {
        device_24cxx_write_byte(addr++, *pBuf);
        *pBuf++;
    }

    return (0);
}

/****************************************************************************/
/*                                                                          */
/*  End of file.                                                            */
/*                                                                          */
/****************************************************************************/
